import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xmshop/app/modules/cart/views/cart_item_num_view.dart';
import 'package:xmshop/app/serives/httpsClient.dart';
import 'package:xmshop/app/serives/screenAdapter.dart';

import '../controllers/cart_controller.dart';

class CartItemView extends GetView {
  final Map cartItem;
  @override
  final CartController controller = Get.find();

  CartItemView(this.cartItem, {Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(ScreenAdapter.height(20)),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(
                  width: ScreenAdapter.height(2),
                  color: const Color.fromARGB(178, 240, 236, 236)))),
      child: Row(
        children: [
          SizedBox(
            width: ScreenAdapter.width(100),
            child: Checkbox(
              activeColor: Colors.red,
              value: cartItem["checked"],
              onChanged: (value) {
                controller.checkCartItem(cartItem);
              },
            ),
          ),
          Container(
            width: ScreenAdapter.width(260),
            padding: EdgeInsets.all(ScreenAdapter.height(24)),
            margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
            child: Image.network(
              HttpsClient.replaceUri(cartItem["pic"]),
              fit: BoxFit.fitHeight,
            ),
          ),
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "${cartItem["title"]}",
                style: TextStyle(
                    fontSize: ScreenAdapter.fontSize(36),
                    fontWeight: FontWeight.bold),
              ),
              SizedBox(
                height: ScreenAdapter.height(20),
              ),
              Row(
                children: [Chip(label: Text(cartItem["selectedAttr"]))],
              ),
              SizedBox(height: ScreenAdapter.height(20)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "¥${cartItem["price"]}",
                    style: TextStyle(
                        fontSize: ScreenAdapter.fontSize(38),
                        color: Colors.red),
                  ),
                  CartItemNumView(cartItem)
                ],
              )
            ],
          ))
        ],
      ),
    );
  }
}
